//
//  ViewObjectsViewController.m
//  ViewObjects
//
//  Created by iMac-hxsd on 12-2-25.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "ViewObjectsViewController.h"

@implementation ViewObjectsViewController

@synthesize userNameField;
@synthesize passwordField;
@synthesize remember;
@synthesize rememberMessage;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark - Methods 

// 关闭键盘
- (IBAction) textFieldDoneEdition: (id) sender
{
    [sender resignFirstResponder];
}

// 点击背景关闭键盘
- (IBAction) closeKeyBoard: (id) sender
{
    [userNameField resignFirstResponder];
    [passwordField resignFirstResponder];
}

// 显示/隐藏记住密码提示信息
- (IBAction) displayRememberMessage: (id) sender
{
    UISwitch *rememberSwitch = sender;
    if (rememberSwitch.isOn) 
    {
        [rememberMessage setHidden:NO];
    }
    else
    {
        [rememberMessage setHidden:YES];
    }
}

// 登录
- (IBAction) login : (id)sender
{
    NSString *message = @"";
    if ([userNameField.text length] < 1)
    {
        message = @"请填写用户名";
    }
    else if ([passwordField.text length] < 6)
    {
        message = @"密码最少为6位";
    }
    else
    {
        message = @"登录成功！";
    }
    
    UIAlertView *al = [[UIAlertView alloc]
                       initWithTitle:@"提示信息" 
                       message:message 
                       delegate:self
                       cancelButtonTitle:@"确定" 
                       otherButtonTitles:nil
                       ];
    [al show];
}

@end
